$(function () {

    template.defaults.imports.dateFormat = function(date) {
        const dt = new Date(date)
      
        var y = dt.getFullYear()
        var m = padZero(dt.getMonth() + 1)
        var d = padZero(dt.getDate())
      
        var hh = padZero(dt.getHours())
        var mm = padZero(dt.getMinutes())
        var ss = padZero(dt.getSeconds())
      //过滤器函数 一定要将正确的处理结果return出去 否则过滤不生效
        //注意: 所有函数被调用后 都会有一个return值 默认是underfined
        return y + '-' + m + '-' + d + ' ' + hh + ':' + mm + ':' + ss
      }
      
      // 定义补零的函数
      function padZero(n) {
        return n > 9 ? n : '0' + n
      }
    initArtList()
    function initArtList() {
        $.ajax({
            method: 'GET',
            url: 'http://124.223.14.236:8060/admin/ydd_article/list',
            headers : {
                'x-token': "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaW5mbyI6eyJpZCI6IjEiLCJsb2dpbl9uYW1lIjoiYWRtaW4iLCJwYXNzd29yZCI6Ijk2ZTc5MjE4OTY1ZWI3MmM5MmE1NDlkZDVhMzMwMTEyIiwibmFtZSI6IlRoaW5rSlPkuIDlk6UiLCJlbWFpbCI6Imhld3UxMTIyQDE2My5jb20iLCJwaG9uZSI6IjE3MzQyMDY1OTA5IiwibG9naW5faXAiOiI6OjEiLCJsb2dpbl9kYXRlIjoiMjAxOC0wMS0wOCAxNjoyMjo1MSIsImNyZWF0ZV9kYXRlIjoiMjAxNy0xMi0xNCAxMTo1Mjo0NiIsInVwZGF0ZV9kYXRlIjoiMjAyMS0wOS0wOCAxOTo0MzowMyIsImRlbF9mbGFnIjoiMCIsInJvbGVfaWQiOlsiMWM1NGUwMDNjMWZjNGRjZDliMDg3ZWY4ZDQ4YWJhYzMiXSwic3RhdHVzIjoxLCJkZWZhdWx0X2RhdGEiOiIxIiwicm9sZW5hbWUiOlsi6LaF57qn566h55CG5ZGYIl19LCJpYXQiOjE2NTQ3ODY5MzZ9.VFu0p1w6gPzm9t3w5zDqnciWVSbFG6ZIz3ReIC2ylEQ"
            },
            data: {
                start_time:'',
                end_time: '',
                title: $('[name=title]').val(),
                cateid: '',
                page: '',
                limit: '',
                
            },
            success: function (res) {
                console.log(res);
                var htmlStr = template('tpl_art', res)
                $('tbody').html(htmlStr)
            }
        })
    }

    
})